# Author :targacute

# ==========================
# ===  General settings  ===
# ==========================
# config color of tmux
#export TMUX_TMPDIR="$HOME/.config/tmux/tmp"
# Add truecolor support
set -g default-terminal "screen-256color"
#set-option -ga terminal-overrides ",*256col*:Tc"
set-option -sa terminal-overrides ",xterm-256color:RGB"

set -g status-interval 1

set -g history-limit 10000

set -s focus-events on
# Index starts from 1
set -g base-index 1
setw -g pane-base-index 1   # make pane numbering consistent with windows

setw -g automatic-rename on # rename window to reflect current program
set -g renumber-windows on  # renumber windows when a window is closed

set -g set-titles on                        # set terminal title
set -g set-titles-string '#h ❐ #S ● #I #W'

# reduce the time when type prefix
set -s escape-time 0

setw -g monitor-activity on
set -g visual-activity off

set -g repeat-time 400
# ==========================
# ===    Colorscheme     ===
# ==========================
set -g message-style fg='colour222',bg='colour238'
set -g message-command-style fg='colour222',bg='colour238'
set -g pane-border-style fg='colour238'
set -g pane-active-border-style fg='colour154'

set-option -g status-style                 fg=colour15,bg=#282c34
set-option -g pane-border-style            fg=green
set-option -g pane-active-border-style     fg=yellow
set-option -g window-status-activity-style fg=colour111

# =====================================
# ===    Appearence and status bar  ===
# ======================================
source-file ~/.config/tmux/statusline/magnet-line.tmux
#source-file ~/.config/tmux/statusline/power-line.tmux

# ==========================
# ===   Key bindings     ===
# ==========================
#setw -g xterm-keys on
# use vi mode
# 进入vi模式，prefix + [，退出q
setw -g mode-keys vi

# set prefix key
set -g prefix C-Space
# unbind the default prefix key C-b
unbind C-b
unbind '"'
unbind %
bind - split-window -h -c "#{pane_current_path}"
bind = split-window -v -c "#{pane_current_path}"

# switch window
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# change the window size
bind -r H resize-pane -L 10
bind -r J resize-pane -D 10
bind -r K resize-pane -U 10
bind -r L resize-pane -R 10

# keload the tmux config
bind r source-file ~/.tmux.conf \; display "Configuration Reloaded"

# ==========================
# ===   Plugin Resurrect ===
# ==========================

# prefix + ctrl + s -> save;prefix + ctrl + r -> recover
# tmux-resurrect
set -g @resurrect-capture-pane-contents 'on'
# save vim session
set -g @resurrect-strategy-vim 'session'
# save neovim session
set -g @resurrect-strategy-nvim 'session'

# ============================
# ===       Plugins        ===
# ============================
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-cpu'
# save session
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'

set -g @plugin 'tmux-plugins/tmux-prefix-highlight'
set -g @plugin 'tmux-plugins/tmux-battery'
set -g @plugin 'thewtex/tmux-mem-cpu-load'
set -g @plugin 'tmux-plugins/tmux-copycat'
set -g @plugin 'tmux-plugins/tmux-yank'
set -g @prefix_highlight_show_copy_mode 'on'
set -g @prefix_highlight_copy_mode_attr 'fg=white,bg=blue'
set -g @continuum-save-interval '15'

if "test ! -d ~/.tmux/plugins/tpm" \
   "run 'git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm && ~/.tmux/plugins/tpm/bin/install_plugins'"

run '~/.tmux/plugins/tpm/tpm'
